﻿/***************************************
*打开窗口相关
****************************************/
function OpenDialog(targetUrl, width, height, useCurrentDir)
{
    //是否在路径前加入当前路径
    if ((typeof useCurrentDir != "boolean") || (useCurrentDir == true))
    {//加
        targetUrl = systemCurrentDirectory + targetUrl;
    }
    var currentTime = new Date();
    var path = systemAbsolutePath + "/Dialog.aspx?system_renew=" + currentTime.getTime() + "&targetUrl=" + encodeURIComponent(targetUrl);

    return window.showModalDialog(path, window, "unadorned:1;status:1;help:0;edge:raised;scroll:0;dialogHeight:" + height + "px;" + "dialogWidth:" + width + "px;")
}
function OpenWindow(targetUrl, width, height, useCurrentDir, top, left)
{
    //使用Frame作为窗口
    if (systemWindowStyle == 'Frame')
    {
        //是否在路径前加入当前路径
        if ((typeof useCurrentDir != "boolean") || (useCurrentDir == true))
        {//加
            targetUrl = systemCurrentDirectory + targetUrl;
        }
        var path = systemAbsolutePath + "/Window.aspx?targetUrl=" + encodeURIComponent(targetUrl);
        var oTarget = document.getElementById("WindowFrame");
        if (oTarget != null)
        {
            document.body.removeChild(oTarget);
        }
        var bodyWidth = document.body.clientWidth;
        var bodyHeight = document.body.clientHeight;
        var scrLeft = document.body.scrollLeft;
        var scrTop = document.body.scrollTop;
        var posTop;
        if (typeof top == "number")
        {
            posTop = top;
        }
        else
        {
            posTop = (bodyHeight - height) / 2 + scrTop;
        }
        var posLeft;
        if (typeof left == "number")
        {
            posLeft = left;
        }
        else
        {
            posLeft = (bodyWidth - width) / 2 + scrLeft;
        }
        var html = "<IFRAME ID='WindowFrame' src='" + path + "' SCROLLING='no' frameborder='0' ";
        html += "progid:DXImageTransform.Microsoft.[glass](duration=1) ";
        html += "width='" + width + "' height='" + height + "'";
        html += " style='position:absolute;left:" + posLeft + "px;top:" + posTop + "px;'></IFRAME>";
        var oFrame = document.createElement(html);
        document.body.insertAdjacentElement("afterBegin", oFrame);
    }
    //使用Window作为窗口
    else if (systemWindowStyle == "Window")
    {
        var leftPos = (screen.width - width) / 2;
        var topPos = (screen.height - height) / 2;
        var status = "top=40,left=" + leftPos + ",top=" + topPos + ",height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
        var openedWindow = window.open(targetUrl, null, status);
        openedWindow.focus();
    }
}
/*************************
自定义开新窗口函数 -- 选择窗口
**************************/
function OpenSelect(pageName, textBoxID, width, height, disableServerClick)
{
    //打开对话框
    var url = systemAbsolutePath + "/Common/" + pageName;
    var result = OpenDialog(url, width, height, false);

    if ((result != undefined) && (result != ""))
    {
        //设定文本框
        result = result.split(",");
        var textBox = document.all(textBoxID);
        if (textBox != null)
        {
            textBox.value = result[0];
            textBox.focus();
            textBox.select();
        }
    }
    //是否禁止服务端点击,默认为false
    if ((typeof disableServerClick != "boolean") || (disableServerClick == true))
    {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
        return false;
    }
}
/*****************************
当单击radioButton时Focus inputControl
*****************************/
function FocusInputOnClickRadioButton(radioButton, inputControl)
{
    if (radioButton.checked)
    {
        inputControl.focus();
        if (inputControl.isTextEdit)
        {
            inputControl.select();
        }
    }
}

/*****************************
当Focus inputControl时选中radioButton
*****************************/
function CheckRadioButtonOnInputFucus(radioButton)
{
    radioButton.checked = true;
}

/*****************************
当radioButton选中时检查与它关联的输入控件值是否为空
*****************************/
function ValidOnRadioButtonChecked(radioButtonID, inputControlID)
{
    var radioButton = document.getElementById(radioButtonID);
    if (radioButton.checked)
    {
        var inputControl = document.getElementById(inputControlID);
        if (inputControl.value.trimChar() != "")
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    return true;
}

/*****************************
取得查询字串
*****************************/
function GetQueryString(url, name)
{
    var result;
    result = url.match("(\\?|&)" + name + "=([^&$]*)");
    result = (result == null || result.length == 1) ? "" : result[2];
    return result;
}

/*****************************
给字符串添加去除空格或字符函数
*****************************/
String.prototype.trimChar = function(c)
{
    // 用正则表达式将前后空格或指定字符 
    // 用空字符串替代。  
    if (c == null)
    {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
    else
    {
        return this.replace(new RegExp("(^" + c + "*)|(" + c + "*$)", "g"), "");
    }
} 

function IsDateChar() 
{ 
    if (!String.fromCharCode(event.keyCode).match(/[0-9-\/]/g)) 
    {
        event.returnValue=false;
        return false;
    }
    return true; 
}

function IsDateTimeChar() 
{
    if (!String.fromCharCode(event.keyCode).match(/[0-9- \/:]/g))
    {
        event.returnValue=false;
        return false;
    }
    return true; 
}

